Java Introduction

It is expected that the information presented here will enable the reader to gain an introductory knowledge of the Java environment and how Java is used.

History

http://java.sun.com/features/1998/05/birthday.html

What is Java?

Java Langauge, Java Virtual Machine and Java Platform.

How to use Java

Java Uses, Java Strengths and Weaknesses

Java Language

A simple, object-oriented, network-centric, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, dynamic language.

The design requirements of the Java programming language are driven by the nature of the computing environments in which software must be deployed. The massive growth of the Internet and the World Wide Web leads us to a completely new way of looking at development and distribution of software. To live in the world of electronic commerce and distribution, Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks. Operating on multiple platforms in heterogeneous networks invalidates the traditional schemes of binary distribution, release, upgrade, patch, and so on. To survive in this jungle, the Java programming language must be architecture neutral, portable, and dynamically adaptable. The system that emerged to meet these needs is simple, so it can be easily programmed by most developers; familiar, so that current developers can easily learn the Java programming language; object oriented, to take advantage of modern software development methodologies and to fit into distributed client-server applications; multithreaded, for high performance in applications that need to perform multiple concurrent activities, such as multimedia; and interpreted, for maximum portability and dynamic capabilities. Also see Supplemental Information

Simple

The Java language environment creates an extremely attractive middle ground between very high-level and portable but slow scripting languages and very low level and fast but non-portable and unreliable compiled languages. The Java language fits somewhere in the middle of this space. In addition to being extremely simple to program, highly portable and architecture neutral, the Java language provides a level of performance that's entirely adequate for all but the most compute-intensive applications. Java is a full programming language that has a clean syntax and helps to prevent programmers from making coding errors with facilities such as array bounds checking and not supporting pointers.

Object-oriented

This is, unfortunately, one of the most overused buzzwords in the industry. But object-oriented design is very powerful because it facilitates the clean definition of interfaces and makes it possible to provide reusable "software ICs." Simply stated, object-oriented design is a technique that focuses design on the data (i.e. objects) and on the interfaces to it. To make an analogy with carpentry, an "object-oriented" carpenter would be mostly concerned with the chair he was building, and secondarily with the tools used to make it; a "non-object-oriented" carpenter would think primarily of his tools. Object-oriented design is also the mechanism for defining how modules "plug and play."

To be truly considered "object oriented", a programming language should support at a minimum four characteristics:

Encapsulation--implements information hiding and modularity (abstraction).
Polymorphism--the same message sent to different objects results in behavior that's dependent on the nature of the object receiving the message.
Inheritance--you define new classes and behavior based on existing classes to obtain code re-use and code organization.
Dynamic binding--objects could come from anywhere, possibly across the network. You need to be able to send messages to objects without having to know their specific type at the time you write your code. Dynamic binding provides maximum flexibility while a program is executing.

Java meets these requirements nicely, and adds considerable run-time support to make your software development job easier.

Network-centric

Designed with a distributed, networked computing environment in mind, Java makes it easy to work with resources across a network and to create network-based applications using client/sever or multi-tier architectures.

Interpreted

Java is both an interpreted and compiled language. Java source code is compiled into bytecode using the Java compiler. These bytecodes are binary and architecturally neutral (platform-independent). The Java runtime environment interprets the bytecodes for each specific platform to execute the Java program. The interpreter can hinder performance but this can be overcome by the use of a tool called a just-in-time (JIT) compiler. A JIT compiler compiles Java methods into native code at the time of execution by the runtime environment. Otherwise, the Java methods are interpreted by the Java Virtual Machine in the runtime environment. This combination of compilation and interpretation facilitate security and stability and alleviates concerns about version mismatches.

Robust

Java is intended for writing programs that must be reliable in a variety of ways. Java puts a lot of emphasis on early checking for possible problems, later dynamic (runtime) checking, and eliminating situations that are error prone. Java has a pointer model that eliminates the possibility of overwriting memory and corrupting data. Instead of pointer arithmetic, Java has true arrays. This allows subscript checking to be performed. In addition, it is not possible to turn an arbitrary integer into a pointer by casting.

Secure

Java is intended for use in networked/distributed environments. Toward that end, a lot of emphasis has been placed on security. Java enables the construction of virus-free, tamper-free systems. The authentication techniques are based on public-key encryption. There is a strong interplay between "robust" and "secure." For example, the changes to the semantics of pointers make it impossible for applications to forge access to data structures or to access private data in objects that they do not have access to. This closes the door on most activities of viruses. Java Security

Architecture Neutral

Java was designed to support applications on networks. In general, networks are composed of a variety of systems with a variety of CPU and operating system architectures. To enable a Java application to execute anywhere on the network, the compiler generates an architecture-neutral object file format--the compiled code is executable on many processors, given the presence of the Java runtime system. The Java Platform facilitates the notion of "Write Once, Run Anywhere".

Portable

Java is portable is three aspects. The first is due to the architectural neutral aspect on the Java platform. The second is that distribution of Java programs is easy due to its network-centric aspect. Finally, Java is portable because there are no implementation dependent aspects of the language specification. For example, an int (integer) is a 32-bit signed two’s complement number no matter what platform the Java platform is run on.

High-Performance

While the performance of interpreted bytecodes is usually more than adequate, there are situations where higher performance is required. The bytecodes can be translated on the fly (at runtime) into machine code for the particular CPU the application is running on (using a JIT compiler). For those accustomed to the normal design of a compiler and dynamic loader, this is somewhat like putting the final machine code generator in the dynamic loader. The bytecode format was designed with generating machine codes in mind, so the actual process of generating machine code is generally simple. Efficient code is produced: the compiler does automatic register allocation and some optimization when it produces the bytecodes.

Multithreaded

Writing multithreaded applications is important for Internet applications. Sophisticated computer users become impatient with the do-one-thing-at-a-time mindset of the average personal computer. Users perceive that their world is full of multiple events all happening at once, and they like to have their computers work the same way. Unfortunately, writing programs that deal with many things happening at once can be much more difficult than writing in the conventional single-threaded C and C++ style. You can write multithreaded applications in languages such as C and C++, but the level of difficulty goes up by orders of magnitude, and even then there are no assurances that vendors' libraries are thread-safe. The term thread-safe means that a given library function is implemented in such a manner that it can be executed by multiple concurrent threads of execution. The major problem with explicitly programmed thread support is that you can never be quite sure you have acquired the locks you need and released them again at the right time. If you return from a method prematurely, for instance, or if an exception is raised, for another instance, your lock has not been released; deadlock is the usual result. Java makes writing multithreaded programs easier than most other alternatives.

Dynamic Language

Java is both dynamic and extensible. Java code is organized in modular object-oriented units called classes. Classes are stored is separate files and are loaded into the Java interpreter only when needed. This means that an application can decide as it is running what classes it needs and can load then when it needs them. It also means that a program can dynamically extend itself by loading the classes it needs to expand its functionality. The network-centric design of the Java platform means that a Java application can dynamically extend itself by loading new classes over a network. An application that takes advantage of these features ceases to be a monolithic block of code. Instead, it becomes an interacting collection of independent software components. Thus, Java enables a powerful new metaphor of application design and development.

Supplemental Information

Java White Papers: http://java.sun.com/docs/white/index.html

Java Overview: http://java.sun.com/docs/overviews/java/java-overview-1.html

Language Environment: http://java.sun.com/docs/white/langenv/
Section 2.2 is particularly interesting about why certain features are not in Java.
Some of the sections may not be relevant until covered in this course.
Java in a Nutshell 3rd Edition pg. 80-81 has more Java and C differences.

Language Specification: http://java.sun.com/docs/books/jls/html/index.html

Java Virtual Machine

The JVM is the architectural specific (hardware and operating system) component of the Java platform that runs Java programs. The JVM interprets Java bytecodes in a Java class and performs the appropriate behavior. The JVM is like a virtual computer that has its own instruction set. The JVM must be implement on a particular hardware and operating system for that physical computer to be able to execute Java programs. However, the Java programs are targeted to run on the virtual computer. This is the heart of what makes Java portable, architecture neutral and secure.

JVM: http://java.sun.com/docs/books/vmspec/index.html

JVM: http://java.sun.com/docs/books/vmspec/2nd-edition/html/Introduction.doc.html particularly sections 1.1 & 1.2.

Java Byte Codes

The machine language of the JVM is the Java byte codes, as defined in the JVM specification. The specification defines how class parts, like variables, methods, and modifiers, are stored in Java class files. A Java byte code-generating compiler takes a source file and converts the appropriate input to Java byte code instructions in a .class file. The input does NOT need to be based on the Java language, though. In fact, there are several cross compilers that take source files from other languages, like Ada, COBOL, or Delphi, and generate Java byte codes.

 

Java Platform

The Java Platform is a set of predefined classes known as the runtime environment or Core API. Any implementation of Java (language, virtual machine and platform) must support these predefined classes according to their specification on the target hardware and operating system. This ensures Java programmers that they can use this API in their programs and that it will be supported in any Java Platform. These predefined classes are organized into packages and define such functionality as Input/Output, networking, graphics, user-interface creation, security, and much more. These packages offer a rich breadth and depth of functionality which can rival and act as an alternative to an operating system specific API. The Java Platform is another key ingredient in the portability of Java.

Java Platform: http://java.sun.com/docs/white/platform/javaplatformTOC.doc.html

 

Java Uses

Applets

Applets are essentially applications that run inside a Java-enabled browser.

Client/GUI applications

Client, GUI applications have a graphical interface and stand on their own. In other words, they do not need a browser to execute. However, they do need the Java runtime environment on the client computer.

Command line applications

Command line applications are stand-alone applications whose user interface is a command line. For example, they can be run from the MS-DOS command prompt.

Server applications

Server applications are stand-alone applications that run on a server.

Servlets

Java servlets offer a fast, powerful, portable replacement for Common Gateway Interface (CGI) scripts. Issues dealt with in servlet programming are:

http://java.sun.com/products/servlet/

JavaServer Pages (JSP) technology is an extension of the servlet technology created to support authoring of HTML and XML pages. It makes it easier to combine fixed or static template data with dynamic content. http://java.sun.com/products/jsp/

Components

Components are classes that can be grouped together to form packages.

Packages

Packages are a collection of classes that functionally belong together; similar to a library of functions in other languages’ jargon.

Embedded applications

Java programs can be run within an embedded computer such as an oscilloscope.

Pen-based programs

Pen-based program can be run in a hand-held device.

 

Java Security

Java provides a secure environment through four major categories. These categories are briefly defined here and a more thorough discussion will be provided later. [Insert link to Java Security and Cryptography]

The first category of security is the Java Language. At this level the language syntax and semantic define security features. This includes such features as not allowing illegal memory references (no pointer arithmetic), reclaiming memory through garbage collection, strong type casting and protection modifiers for variables, methods and objects.

The second category of security is the Java Virtual Machine. At this level the virtual machine acts as a secure "sandbox" in which Java programs can run. The "sandbox" verifies that only valid accesses to the underlying operating system and hardware is allowed. This is done by the class loader, runtime-checking, the security manager and access control mechanisms.

The third category of security is the Java Core API. At this level the Java programmer can assume that the methods in the Core API are written to ensure security. This assumption is based upon using a Java Virtual Machine and Core API implementation that has been certified by Sun to be secure. The Sun JVM and Core API are of course certified and Sun provides a reference model that other suppliers of a JVM and Core API can certify their implementations against.

The fourth category of security is the application itself. Cryptographic facilities can be used to certify that a Java application or applet can be trusted and thus some of the restrictions placed upon applets at the JVM level can be loosened so as to give an applet more functionality.

 

Java Strengths and Weaknesses

Java strengths stems from the fact that it is object-oriented, platform independent, secure, has a clean syntax, helps to prevent programmers from making coding errors, and has array bounds checking. The weaknesses are performance (though this is not too bad and there are remedies) and it is still maturing as an environment.

[Index]